import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '@/views/Index.vue'
import About from '@/views/About.vue'
import News from '@/views/News.vue'
import NewsDetail from '@/views/NewsDetail.vue'
import User from '@/views/User.vue'
import UserInfo from '@/views/User/UserInfo'
import UserOrder from '@/views/User/UserOrder'
import UserWelcome from '@/views/User/UserWelcome'
import Login from '@/views/Login.vue'
import NotFound from '@/views/NotFound.vue'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    component: Index,
    meta: { title: '首页' }
  }, {
    path: '/about',
    component: About,
    name: 'gywm',
    meta: { title: '关于我们' }
  }, {
    path: '/news',
    component: News,
    meta: { title: '新闻列表' }
  },
  {
    path: '/news/:id',
    component:
    NewsDetail,
    props: true,
    name: 'newsdetail',
    meta: { title: '新闻详情页' }
  },
  {
    path: '/user',
    component: User,
    redirect: '/user/index',
    meta: { title: '用户中心', needLogin: true },
    children: [{
      path: '/user/index',
      component: UserWelcome,
      meta: { title: '用户中心-欢迎您', needLogin: true }
    },
    {
      path: '/user/order',
      component: UserInfo,
      meta: { title: '用户中心-订单', needLogin: true }
    },
    {
      path: '/user/info',
      component: UserOrder,
      meta: { title: '用户中心-资料', needLogin: true }
    }]
  }, {
    path: '/login',
    component: Login,
    meta: { title: '登录' }
  },
  // 千万记得404页面一定要放在最后去配置
  {
    path: '/404',
    component: NotFound,
    meta: { title: '404' }
  },
  {
    path: '*',
    redirect: '/404'
  }
]
const router = new VueRouter({
  routes: routes
})

export default router
